﻿using Dapper;
using Estsh.Core.Base;
using Estsh.Core.Model.Extend;
using Estsh.Core.Model.Extend.IFModels;
using Estsh.Core.Model.Extend.Models;
using Estsh.Core.Model.Result;
using Estsh.Core.Models;
using Estsh.Core.Services;
using Estsh.Core.Wms.IRepositories;
using Estsh.Core.Wms.IServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Estsh.Core.Wms.Services
{
    /// <summary>
    /// ERP接口
    /// </summary>
    public class ERPInterfaceService : BaseService<BaseEntity>, IERPInterfaceService
    {
        private readonly IERPInterfaceRepository repository;
        public ERPInterfaceService(IERPInterfaceRepository _repository) : base(_repository)
        {
            repository = _repository;
        }
        public WmsInterfaceResult GetInvokInterfaceData(ActionMessage actionMessage)
        {
            WmsInterfaceResult rfInfo = repository.GetInvokInterfaceData(actionMessage);
            return rfInfo;
        }
        /// <summary>
        /// 从SAP传递物料基本信息到WMS
        /// </summary>
        /// <param name="sapPt"></param>
        /// <returns></returns>
        public WmsInterfaceResult MaterialMasterMethod(string sid, List<SapPtInterface_Extend> sapPt)
        {
            WmsInterfaceResult rfInfo = repository.MaterialMasterMethod(sid, sapPt);
            return rfInfo;
        }

        /// <summary>
        /// 从SAP传递供应商基本信息到WMS
        /// </summary>
        /// <param name="sapPt"></param>
        /// <returns></returns>
        public WmsInterfaceResult SupplierMasterMethod(string sid, List<SapSuInterface> sapSu)
        {
            WmsInterfaceResult rfInfo = repository.SupplierMasterMethod(sid, sapSu);
            return rfInfo;
        }

        /// <summary>
        /// 从SAP传递客户基本信息到WMS
        /// </summary>
        /// <param name="sapPt"></param>
        /// <returns></returns>
        public WmsInterfaceResult CustomerMasterMethod(string sid, List<SapCuInterface> sapCu)
        {
            WmsInterfaceResult rfInfo = repository.CustomerMasterMethod(sid,sapCu);
            return rfInfo;
        }

        /// <summary>
        /// 从SAP传递物料号与客户物料号对照信息到WMS
        /// </summary>
        /// <param name="sapPt"></param>
        /// <returns></returns>
        public WmsInterfaceResult CustomerItemMasterMethod(string sid, List<SapPtcptInterface> sapPtcpt)
        {
            WmsInterfaceResult rfInfo = repository.CustomerItemMasterMethod(sid, sapPtcpt);
            return rfInfo;
        }

        /// <summary>
        /// MBOM同步到MES系统
        /// </summary>
        /// <param name="sapBom"></param>
        /// <returns></returns>
        public WmsInterfaceResult BomMasterMethod(string sid, List<SapBomInterface_Extend> sapBom)
        {
            WmsInterfaceResult rfInfo = repository.BomMasterMethod(sid, sapBom);
            return rfInfo;
        }
        /// <summary>
        /// SAP系统把ASN传递到WMS用于采购收货
        /// </summary>
        /// <param name="sapAsn"></param>
        /// <returns></returns>
        public WmsInterfaceResult ASNDataMethod(string sid, List<SapAsnInterface> sapAsn)
        {
            WmsInterfaceResult rfInfo = repository.ASNDataMethod(sid, sapAsn);
            return rfInfo;
        }

        /// <summary>
        /// SAP系统把PO传递到WMS用于采购收货
        /// </summary>
        /// <param name="sapDspo"></param>
        /// <returns></returns>
        public WmsInterfaceResult PODataMethod(string sid, List<SapDspoInterface_Extend> sapDspo)
        {
            WmsInterfaceResult rfInfo = repository.PODataMethod(sid, sapDspo);
            return rfInfo;
        }

        /// <summary>
        /// SAP系统将一定期间内待发运交货单信息发布到WMS用于后续捡配发货
        /// </summary>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public WmsInterfaceResult SalesAndDeliveryPlanMethod(string sid, List<SapDnInterface> sapDns)
        {
            WmsInterfaceResult rfInfo = repository.SalesAndDeliveryPlanMethod(sid, sapDns);
            return rfInfo;
        }

        /// <summary>
        /// SAP把物料的零星出(入）指令传到WMS
        /// </summary>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public WmsInterfaceResult SporadicEntryAndExitMethod(string sid, List<SapMiscoInterface> sapMiscos)
        {
            WmsInterfaceResult rfInfo = repository.SporadicEntryAndExitMethod(sid, sapMiscos);
            return rfInfo;
        }

        /// <summary>
        /// 盘点开始时，SAP冻结库存，并把盘点表传到WMS
        /// </summary>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public WmsInterfaceResult InventoryListMethod(string sid, List<SapCycoInterface> sapCycos)
        {
            WmsInterfaceResult rfInfo = repository.InventoryListMethod(sid, sapCycos);
            return rfInfo;
        }

        /// <summary>
        /// SAP把盘点差异转移到差异库的结果传到WMS，使得WMS可以根据盘点结果调整库存
        /// </summary>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public WmsInterfaceResult InventoryDifferenceAdjustmentMethod(string sid, List<SapDifoInterface> sapDifos)
        {
            WmsInterfaceResult rfInfo = repository.InventoryDifferenceAdjustmentMethod(sid, sapDifos);
            return rfInfo;
        }

        public sys_if_rec_config GetEquipReqIFConfig(string Code)
        {
            sys_if_rec_config rfInfo = repository.GetEquipReqIFConfig(Code);
            return rfInfo;
        }

        public WmsInterfaceResult WorkCenterMethod(string sid, List<SapWorkcenter> workcenters)
        {
            WmsInterfaceResult result = repository.WorkCenterMethod(sid,workcenters);
            return result;
        }

        public WmsInterfaceResult ProcessInfoMethod(string sid, List<SapProcessinfo> sapProcessinfos)
        {
            WmsInterfaceResult result = repository.ProcessInfoMethod(sid, sapProcessinfos);
            return result;
        }

        public WmsInterfaceResult StockInfoMethod(string sid, List<SapStockinfo> sapStockinfos)
        {
            WmsInterfaceResult result = repository.StockInfoMethod(sid, sapStockinfos);
            return result;
        }

        public WmsInterfaceResult LogisticsMethod(string sid, List<WmsLogistics> logistics)
        {
            WmsInterfaceResult result=repository.WmsLogisticsMethod(sid, logistics);
            return result;
        }

        public WmsInterfaceResult PersonMethod(string sid, List<WmsPerson> people)
        {
            WmsInterfaceResult result = repository.PersonMethod(sid, people);
            return result;
        }

        public WmsInterfaceResult WareHouseMethod(string sid, List<WmsWh> wmsWhs)
        {
            WmsInterfaceResult result=repository.WareHouseMethod(sid, wmsWhs);
            return result;
        }

        public WmsInterfaceResult ZoneMethod(string sid, List<WmsZone> whlocates)
        {
            WmsInterfaceResult result=repository.ZoneMethod(sid, whlocates);
            return result;
        }

        public WmsInterfaceResult QCMethod(string sid, List<WmsToqce> wmsToqcs)
        {
            WmsInterfaceResult result = repository.QCMethod(sid, wmsToqcs);
            return result;
        }

        public WmsInterfaceResult MaterialGroupMethod(string sid, List<SapwlGroup> sapwlGroup)
        {
            WmsInterfaceResult result = repository.MaterialGroupMethod(sid, sapwlGroup);
            return result;
        }
        /// <summary>
        /// 工艺路线主数据
        /// </summary>
        /// <param name="sid"></param>
        /// <param name="sapwlGroup"></param>
        /// <returns></returns>
        public WmsInterfaceResult RouttingMethod(string sid, List<SapRouting> sapwlGroup)
        {
            WmsInterfaceResult result = repository.RouttingMethod(sid, sapwlGroup);
            return result;
        }
        /// <summary>
        /// 工种主数据
        /// </summary>
        /// <param name="sid"></param>
        /// <param name="sapItemListParam"></param>
        /// <returns></returns>
        public WmsInterfaceResult WorkItemMethod(string sid, List<SapWorkItem> sapItemListParam)
        {
            WmsInterfaceResult result = repository.WorkItemMethod(sid, sapItemListParam);
            return result;
        }

        public WmsInterfaceResult SalesHistoryMethod(string sid, List<SapSalesHistory> sapItemListParam)
        {
            WmsInterfaceResult result = repository.SalesHistoryMethod(sid, sapItemListParam);
            return result;
        }

        public WmsInterfaceResult CalculateOrderMethod(string sid, List<SapCalculate> sapItemListParam)
        {
            WmsInterfaceResult result = repository.CalculateOrderMethod(sid, sapItemListParam);
            return result;
        }

        public WmsInterfaceResult MonthReviewResultMethod(string sid, List<SapMonthReviewResult> sapItemListParam)
        {
            WmsInterfaceResult result = repository.MonthReviewResultMethod(sid, sapItemListParam);
            return result;
        }

        public WmsInterfaceResult SalesOrderDateMethod(string sid, List<SapSalessOrder> sapItemListParam)
        {
            WmsInterfaceResult result = repository.SalesOrderDateMethod(sid, sapItemListParam);
            return result;
        }

        public WmsInterfaceResult SalesReviewResultMethod(string sid, List<SapSalesReviewResult> sapItemListParam)
        {
            WmsInterfaceResult result = repository.SalesReviewResultMethod(sid, sapItemListParam);
            return result;
        }

        public WmsInterfaceResult PurachasesReqMethod(string sid, List<SapPurchasesReq> sapItemListParam)
        {
            WmsInterfaceResult result = repository.PurachasesReqMethod(sid, sapItemListParam);
            return result;
        }

        public WmsInterfaceResult SapSalesReviewNoticeMethod(string sid, List<SapSalesReviewNotice> sapItemListParam)
        {
            WmsInterfaceResult result = repository.SapSalesReviewNoticeMethod(sid, sapItemListParam);
            return result;
        }

        public WmsInterfaceResult PurachasesMethod(string sid, List<SapPurchases> sapItemListParam)
        {
            WmsInterfaceResult result = repository.PurachasesMethod(sid, sapItemListParam);
            return result;
        }

        public WmsInterfaceResult SporadicEntryAndExitExtendMethod(string sid, List<SapMiscoInterface_Extend> sapItemListParam)
        {
            WmsInterfaceResult result = repository.SporadicEntryAndExitExtendMethod(sid, sapItemListParam);
            return result;
        }

        public WmsInterfaceResult SalesAndDeliveryPlanExtendMethod(string sid, List<SapDnInterface_Extend> sapDns)
        {
            WmsInterfaceResult result = repository.SalesAndDeliveryPlanExtendMethod(sid, sapDns);
            return result;
        }

        /// <summary>
        /// 设备主数据接口
        /// </summary>
        /// <param name="sid"></param>
        /// <param name="sapItemListParam"></param>
        /// <returns></returns>
        public WmsInterfaceResult EquipmentDataMethod(string sid, List<SapEquipment> sapItemListParam)
        {
            WmsInterfaceResult result = repository.EquipmentDataMethod(sid, sapItemListParam);
            return result;
        }

        public WmsInterfaceResult EquipmentPdLineDataMethod(string sid, List<SapEquipmentPdLine> sapItemListParam)
        {
            WmsInterfaceResult result = repository.EquipmentPdLineDataMethod(sid, sapItemListParam);
            return result;
        }

        public WmsInterfaceResult DepartmentDataMethod(string sid, List<SapDepartment> sapItemListParam)
        {
            WmsInterfaceResult result = repository.DepartmentDataMethod(sid, sapItemListParam);
            return result;
        }

        public WmsInterfaceResult ERPUserDataMethod(string sid, List<SapUser> sapItemListParam)
        {
            WmsInterfaceResult result = repository.ERPUserDataMethod(sid, sapItemListParam);
            return result;
        }
    }
}
